package jw3.c10.controllner;
import jw3.c10.model.Station;
import jw3.c10.utils.DBConnection;
import jw3.c10.utils.QueryByClass;

import jw3.c10.model.Role;
import javax.swing.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.List;
import java.util.Vector;

public class RoleController{
        public static List<Role> getselect(){
           String sql="select RName from role";
           QueryByClass<Role> qc=new QueryByClass<Role>();
           return qc.select(Role.class,sql);
        }
        public static int getRID(String RName){
            String sql="select RID from role where RName=?";
            QueryByClass<Role> qc=new QueryByClass<Role>();
            return qc.select(Role.class,sql,RName).get(0).getRID();
        }
        public static String RRole(int RID){
            String sql="update role set RName=? where RID=?";
            QueryByClass<Role> qc=new QueryByClass<Role>();
            return qc.select(Role.class,sql,RID).get(0).getRName();
        }
    public  static List<Role> cc(){
        QueryByClass<Role> qc=new QueryByClass<>();
        String sql="select RName from  role ";
        return qc.select(Role.class,sql);
    }
    public void showData(String name) {
        Station s=new Station();
        data=new Vector<>();
        String sql = "SELECT  b.RName,a.Station from station  a JOIN role b on\n" +
                " a.RID=b.RID where Station like  ?  ";
        try {
            Connection conn = null;
            try {
                conn = DBConnection.getConnection();
                PreparedStatement ps = conn.prepareStatement(sql);
                JComboBox<String> cmb = new JComboBox<>();
                String c = cmb.getSelectedItem().toString();
//            ps.setString(3,comboBox1.get);
                ps.setString(1, "%"+name+"%");
                ResultSet rs=ps.executeQuery();
                while (rs.next()){
                    Vector<Object> data1=new Vector<>();
                    data1.add(rs.getString("RName"));
                    data1.add(rs.getString("Station"));
                    data.add(data1);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }


        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    private  static Vector<Vector<Object>>data;



}
